package com.yiboshi.rehrs.util;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.*;
import org.apache.http.client.CookieStore;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.AuthSchemes;
import org.apache.http.client.config.CookieSpecs;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.*;
import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
import org.apache.http.conn.socket.ConnectionSocketFactory;
import org.apache.http.conn.socket.PlainConnectionSocketFactory;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.impl.cookie.DefaultCookieSpecProvider;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.beans.BeanInfo;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Method;
import java.net.URI;
import java.net.URLEncoder;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.X509Certificate;
import java.util.*;

/**
 * http请求工具类
 *
 * @author zhuzhe
 * @date 2018/5/3 11:46
 */
@Slf4j
public class HttpClientUtils {

    static ContentType mpegurlType = ContentType.create("application/vnd.apple.mpegurl");
    static RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(
            7000
    ).setConnectTimeout(
            7000
    ).build();


    static Map<String, String> defaultHeaders = new HashMap<>();

    static {
        defaultHeaders.put("user-agent", "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1");
       /* defaultHeaders.put("","");
        defaultHeaders.put("","");
        defaultHeaders.put("","");*/
    }

    public static Document doGetToDoc(String url,
                                      Map<String, String> headers
    ) {
        String s = doGet(url, headers);
        if (StrUtil.isEmpty(s)) {
            return null;
        }
        Document parse = Jsoup.parse(s);
        return parse;
    }

    public static String doGet(String url,
                               Map<String, String> headers
    ) {

        try {
            HttpResponse httpResponse = doGet(url, "", headers, Collections.EMPTY_MAP);
            if (httpResponse == null) {
                //log.error("url:{},headers:{},return null",url,headers);
                return "";
            }
            HttpEntity entity = httpResponse.getEntity();
            String a = EntityUtils.toString(entity, "UTF-8");
            //log.info("url:{}",a);
            return a;
        } catch (Exception e) {
            //log.error("url:{},headers:{},e:{}",url,headers, e.getMessage());
        }
        return "";


    }

    public static byte[] url2byte(String urlStr) {
        HttpResponse response = doGet(urlStr, "", defaultHeaders, null);
        if (response == null) {
            return null;
        }
        try {
            return EntityUtils.toByteArray(response.getEntity());
        } catch (IOException e) {
            log.error("", e.getMessage());
        }
        return null;
    }


    /**
     * get
     *
     * @param host
     * @param path
     * @param headers
     * @param querys
     * @return
     * @throws Exception
     */
    public static HttpResponse doGet(String host, String path,
                                     Map<String, String> headers,
                                     Map<String, String> querys) {
        try {
            HttpClient httpClient = wrapClient(host, path);
            HttpGet request = new HttpGet(buildUrl(host, path, querys));
            setRequestHeaders(headers, request);
            return httpClient.execute(request);
        } catch (Exception e) {
            log.error("host:{},path:{},headers:{},e:{}", host, path, headers, e.getMessage());
            return null;
        }

    }

    public static int doHead(String url) {
        return doHead(url, "", null, null);

    }

    public static int doHead(String host, String path,
                             Map<String, String> headers,
                             Map<String, String> querys) {
        try {
            HttpClient httpClient = wrapClient(host, path);
            HttpHead request = new HttpHead(buildUrl(host, path, querys));
            setRequestHeaders(headers, request);
            return httpClient.execute(request).getStatusLine().getStatusCode();
        } catch (Exception e) {
            log.error("host:{},path:{},headers:{},e:{}", host, path, headers, e.getMessage());
            return 0;
        }

    }

    public static JSONObject doHead(String host,

                                    Map<String, String> headers) {
        try {
            HttpClient httpClient = wrapClient(host, "");
            String s = buildUrl(host, "", null);
            HttpHead request = new HttpHead(s);
            setRequestHeaders(headers, request);
            HttpResponse execute = httpClient.execute(request);
            Header[] allHeaders = execute.getAllHeaders();
            JSONObject headJSON = new JSONObject();
            for (Header header : allHeaders) {
                headJSON.put(header.getName(), header.getValue());
            }
            StatusLine statusLine = execute.getStatusLine();
            headJSON.put("status", statusLine.getStatusCode());
            return headJSON;
        } catch (Exception e) {
            log.error("host:{},headers:{},e:{}", host, headers, e);
            return null;
        }

    }

    public static JSONObject doJsonGet(String api,
                                       Map<String, String> headers, Map<String, String> querys) {
        try {
            HttpResponse httpResponse = doGet(api, "", headers, querys);
            return toJson(httpResponse);
        } catch (Exception e) {
            log.error("doJsonPost fail .api:{},headers:{},querys:{}", api, headers, querys, e);
        }
        return null;
    }

    public static JSONObject doJsonGetProxy(String api,
                                            HttpHost httpHost) {
        try {
            HttpResponse httpResponse = doGet(api, null, httpHost);
            return toJson(httpResponse);
        } catch (Exception e) {
            log.error("doJsonPost fail .api:{} httpHost:{}", api,httpHost.getHostName()+":"+httpHost.getPort(), e);
        }
        return null;
    }

    public static HttpResponse doGet(String url,Map<String, String> headers,  HttpHost httpHost) {
        try {
            HttpClient httpClient = wrapClient(url, "",httpHost);
            HttpGet request = new HttpGet(buildUrl(url, "", null));
            setRequestHeaders(headers, request);
            return httpClient.execute(request);
        } catch (Exception e) {
            log.error("host:{}  headers:{} e:{}", url,  headers, e.getMessage());
            return null;
        }

    }


    public static JSONObject deleteJSON(String api,
                                        Map<String, String> headers, JSONObject jsonObject) {
        try {
            HttpClient httpClient = wrapClient(api, "");
            HttpDeleteWithBody request = new HttpDeleteWithBody(buildUrl(api, "", null));
            setRequestHeaders(headers, request);
            setRequestHeaders(request, "Content-Type", "application/json");
            if (jsonObject != null) {
                request.setEntity(new StringEntity(jsonObject.toJSONString(), "utf-8"));
            }
            HttpResponse httpResponse = httpClient.execute(request);
            return toJson(httpResponse);
        } catch (Exception e) {
            log.error("api:{},message:{}", api, e.getMessage());
            return null;
        }

    }

    public static JSONObject doJsonPost(String api,
                                        Map<String, String> headers,
                                        Map<String, String> bodys) {
        try {
            HttpResponse httpResponse = doPost(api, headers, bodys);
            return toJson(httpResponse);
        } catch (Exception e) {
            log.error("doJsonPost fail .api:{},headers:{},bodys:{}", api, headers, bodys, e);
        }
        return null;
    }

    public static JSONObject doJsonPost(String api,
                                        Map<String, String> headers,
                                        JSONObject jsonObjectBody) {
        try {
            if (headers == null) {
                headers = new HashMap<>();
            }
            headers.put("Content-Type", "application/json");
            HttpResponse httpResponse = doPost(api, "", headers, null, jsonObjectBody.toJSONString());
            StatusLine statusLine = httpResponse.getStatusLine();
            if (statusLine.getStatusCode() == 200) {
                return toJson(httpResponse);
            }
            log.error("doJsonPost fail .api:{} headers:{},res,http code is {}", api, "", statusLine.getStatusCode());
        } catch (Exception e) {
            log.error("doJsonPost fail .api:{} headers:{},jsonObjectBody:{}", api, headers, jsonObjectBody, e);
        }
        return null;
    }

    public static JSONObject doGetmanJsonPost(String api,
                                              Map<String, String> headers,
                                              JSONObject jsonObjectBody, String x_client_id) {
        if (headers == null) {
            headers = new HashMap<>();
        }
        Map newBody = MapBuilder.start("url", api)
                .put("method", "POST")
                .put("body", jsonObjectBody.toJSONString())
                .put("header[Content-Type]", "application/json")
                //.put("header[token]", "application/json")
                .end();
        for (Map.Entry<String, String> stringStringEntry : headers.entrySet()) {
            newBody.put("header[" + stringStringEntry.getKey() + "]", stringStringEntry.getValue());
        }
        String apiNew = "http://getman.cn/api/request";
        Map<String, String> newHeader = new HashMap<>(defaultHeaders);
        newHeader.remove("token");
        //newHeader.put("referer","http://getman.cn/?s=db7ff19efc333e6786ad385f7a787a7a");
        newHeader.put("content-type", "application/x-www-form-urlencoded; charset=UTF-8");
        //newHeader.put("cookie","Hm_lvt_5355caba3fc9511e407d548c7c066f64=1667434424; Hm_lpvt_5355caba3fc9511e407d548c7c066f64=1667438304");
        newHeader.put("x-client-id", x_client_id);
        try {
            HttpResponse httpResponse = doPost(apiNew, newHeader, newBody);
            JSONObject jsonObject = toJson(httpResponse);
            return Optional.ofNullable(jsonObject).map(j -> j.getJSONObject("data")).map(j -> j.getJSONObject("body")).orElse(null);
        } catch (Exception e) {
            log.error("doJsonPost fail .apiNew:{},newHeader:{},newBody:{}", apiNew, newHeader, newBody, e);
        }
        return null;
    }

    public static Document doPostToDoc(String host, Map<String, String> headers,
                                       Map<String, String> bodys) {
        try {

            HttpResponse httpResponse = doPost(host, headers, bodys);
            String string = getString(httpResponse);
            return Jsoup.parse(string);
        } catch (Exception e) {
            log.error("", e);
        }
        return null;

    }


    /**
     * post form
     *
     * @param host
     * @param headers
     * @param bodys
     * @return
     * @throws Exception
     */
    public static HttpResponse doPost(String host,
                                      Map<String, String> headers,
                                      Map<String, String> bodys)
            throws Exception {
        HttpClient httpClient = wrapClient(host, "");
        HttpPost request = new HttpPost(buildUrl(host, "", null));
        setRequestHeaders(headers, request);
        if (bodys != null) {
            List<NameValuePair> nameValuePairList = new ArrayList<>();

            for (String key : bodys.keySet()) {
                nameValuePairList.add(new BasicNameValuePair(key, bodys.get(key)));
            }
            UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, "utf-8");
            formEntity.setContentType("application/x-www-form-urlencoded; charset=UTF-8");
            request.setEntity(formEntity);
        }
        return httpClient.execute(request);
    }


    public static void setRequestHeaders(HttpRequestBase request, String headerKey, String headerValue) {
        for (Map.Entry<String, String> e : defaultHeaders.entrySet()) {
            request.addHeader(e.getKey(), e.getValue());
        }
        setRequestHeaders(null, request);
    }

    public static void setRequestHeaders(Map<String, String> headers, HttpRequestBase request) {
        headers = headers==null?new HashMap<>():headers;
        request.setConfig(requestConfig);
        if (headers != null && !headers.isEmpty()) {
            if (!headers.containsKey("user-agent") && !headers.containsKey("User-Agent")) {
                headers.putAll(defaultHeaders);
            }
        } else {
            headers = defaultHeaders;//2
        }
        for (Map.Entry<String, String> e : headers.entrySet()) {
            request.addHeader(e.getKey(), e.getValue());
        }
    }

    /**
     * Post String
     *
     * @param host
     * @param path
     * @param headers
     * @param querys
     * @param body
     * @return
     * @throws Exception
     */
    public static HttpResponse doPost(String host, String path,
                                      Map<String, String> headers,
                                      Map<String, String> querys,
                                      String body)
            throws Exception {
        HttpClient httpClient = wrapClient(host, path);
        HttpPost request = new HttpPost(buildUrl(host, path, querys));
        setRequestHeaders(headers, request);
        if (StringUtils.isNotBlank(body)) {
            request.setEntity(new StringEntity(body, "utf-8"));
        }
        return httpClient.execute(request);
    }

    public static HttpResponse doPostProxy(String host,
                                           Map<String, String> headers,
                                           byte[] body, HttpHost proxy) throws Exception {
        HttpClient httpClient = wrapClient(host, "", proxy);
        HttpPost request = new HttpPost(buildUrl(host, "", null));
        request.setConfig(requestConfig);
        if (headers == null) {
            headers = new HashMap<>();
            headers.put("user-agent",
                    "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36");
        }
        for (Map.Entry<String, String> e : headers.entrySet()) {
            request.addHeader(e.getKey(), e.getValue());
        }
        if (body != null) {
            ByteArrayEntity byteArrayEntity = new ByteArrayEntity(body);
            //.
            request.setEntity(byteArrayEntity);
        }
        return httpClient.execute(request);

    }

    /**
     * Post stream
     *
     * @param host
     * @param path
     * @param headers
     * @param querys
     * @param body
     * @return
     * @throws Exception
     */
    public static HttpResponse doPost(String host, String path,
                                      Map<String, String> headers,
                                      Map<String, String> querys,
                                      byte[] body)
            throws Exception {
        HttpClient httpClient = wrapClient(host, path);
        HttpPost request = new HttpPost(buildUrl(host, path, querys));
        request.setConfig(requestConfig);
        for (Map.Entry<String, String> e : headers.entrySet()) {
            request.addHeader(e.getKey(), e.getValue());
        }
        if (body != null) {
            ByteArrayEntity byteArrayEntity = new ByteArrayEntity(body);
            //.
            request.setEntity(byteArrayEntity);
        }
        return httpClient.execute(request);
    }

    /**
     * Put String
     *
     * @param host
     * @param path
     * @param headers
     * @param querys
     * @param body
     * @return
     * @throws Exception
     */
    public static HttpResponse doPut(String host, String path,
                                     Map<String, String> headers,
                                     Map<String, String> querys,
                                     String body)
            throws Exception {
        HttpClient httpClient = wrapClient(host, path);
        HttpPut request = new HttpPut(buildUrl(host, path, querys));
        request.setConfig(requestConfig);
        for (Map.Entry<String, String> e : headers.entrySet()) {
            request.addHeader(e.getKey(), e.getValue());
        }
        if (StringUtils.isNotBlank(body)) {
            request.setEntity(new StringEntity(body, "utf-8"));
        }
        return httpClient.execute(request);
    }

    /**
     * Put stream
     *
     * @param host
     * @param path
     * @param headers
     * @param querys
     * @param body
     * @return
     * @throws Exception
     */
    public static HttpResponse doPut(String host, String path,
                                     Map<String, String> headers,
                                     Map<String, String> querys,
                                     byte[] body)
            throws Exception {
        HttpClient httpClient = wrapClient(host, path);
        HttpPut request = new HttpPut(buildUrl(host, path, querys));
        request.setConfig(requestConfig);
        for (Map.Entry<String, String> e : headers.entrySet()) {
            request.addHeader(e.getKey(), e.getValue());
        }
        if (body != null) {
            request.setEntity(new ByteArrayEntity(body));
        }
        return httpClient.execute(request);
    }

    /**
     * Delete
     *
     * @param host
     * @param path
     * @param headers
     * @param querys
     * @return
     * @throws Exception
     */
    public static HttpResponse doDelete(String host, String path,
                                        Map<String, String> headers,
                                        Map<String, String> querys)
            throws Exception {
        HttpClient httpClient = wrapClient(host, path);
        HttpDelete request = new HttpDelete(buildUrl(host, path, querys));
        request.setConfig(requestConfig);
        for (Map.Entry<String, String> e : headers.entrySet()) {
            request.addHeader(e.getKey(), e.getValue());
        }
        return httpClient.execute(request);
    }

    /**
     * 构建请求的 url
     *
     * @param host
     * @param path
     * @param querys
     * @return
     * @throws UnsupportedEncodingException
     */
    private static String buildUrl(String host, String path, Map<String, String> querys) throws UnsupportedEncodingException {
        StringBuilder sbUrl = new StringBuilder();
        if (!StringUtils.isBlank(host)) {
            sbUrl.append(host);
        }
        if (!StringUtils.isBlank(path)) {
            sbUrl.append(path);
        }
        if (null != querys) {
            StringBuilder sbQuery = new StringBuilder();
            for (Map.Entry<String, String> query : querys.entrySet()) {
                if (0 < sbQuery.length()) {
                    sbQuery.append("&");
                }
                if (StringUtils.isBlank(query.getKey()) && !StringUtils.isBlank(query.getValue())) {
                    sbQuery.append(query.getValue());
                }
                if (!StringUtils.isBlank(query.getKey())) {
                    sbQuery.append(query.getKey());
                    if (!StringUtils.isBlank(query.getValue())) {
                        sbQuery.append("=");
                        sbQuery.append(URLEncoder.encode(query.getValue(), "utf-8"));
                    }
                }
            }
            if (0 < sbQuery.length()) {
                sbUrl.append("?").append(sbQuery);
            }
        }
        return sbUrl.toString();
    }

    private static CloseableHttpClient wrapClient(String host, String path, HttpHost httpHost) {
        HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
        if (httpHost != null) {
            httpClientBuilder.setProxy(httpHost);

        }
        CloseableHttpClient httpClient = httpClientBuilder.build();
        if (host != null && host.startsWith("https://")) {
            return sslClient();
        } else if (StringUtils.isBlank(host) && path != null && path.startsWith("https://")) {
            return sslClient();
        }

        return httpClient;
    }

    /**
     * 获取 HttpClient
     *
     * @param host
     * @param path
     * @return
     */
    private static CloseableHttpClient wrapClient(String host, String path) {
        return wrapClient(host, path, null);
    }

    public static CloseableHttpClient wrapClient(String url) {
        return wrapClient(url, "");
    }

    /**
     * 在调用SSL之前需要重写验证方法，取消检测SSL
     * 创建ConnectionManager，添加Connection配置信息
     *
     * @return HttpClient 支持https
     */
    private static CloseableHttpClient sslClient() {
        try {
            // 在调用SSL之前需要重写验证方法，取消检测SSL
            X509TrustManager trustManager = new X509TrustManager() {
                @Override
                public X509Certificate[] getAcceptedIssuers() {
                    return null;
                }

                @Override
                public void checkClientTrusted(X509Certificate[] xcs, String str) {
                }

                @Override
                public void checkServerTrusted(X509Certificate[] xcs, String str) {
                }
            };
            SSLContext ctx = SSLContext.getInstance(SSLConnectionSocketFactory.TLS);
            ctx.init(null, new TrustManager[]{trustManager}, null);
            SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(ctx, NoopHostnameVerifier.INSTANCE);
            // 创建Registry
            RequestConfig requestConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.IGNORE_COOKIES)
                    .setExpectContinueEnabled(Boolean.TRUE).setTargetPreferredAuthSchemes(Arrays.asList(AuthSchemes.NTLM, AuthSchemes.DIGEST))
                    .setProxyPreferredAuthSchemes(Arrays.asList(AuthSchemes.BASIC))
                    .setConnectionRequestTimeout(3000)
                    .setConnectTimeout(3000)
                    .setSocketTimeout(3000)
                    .setExpectContinueEnabled(false)
                    .build();
            Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
                    .register("http", PlainConnectionSocketFactory.INSTANCE)
                    .register("https", socketFactory).build();
            // 创建ConnectionManager，添加Connection配置信息
            PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
            CloseableHttpClient closeableHttpClient = HttpClients.custom().setConnectionManager(connectionManager)
                    .setDefaultRequestConfig(requestConfig)
                    .build();
            return closeableHttpClient;
        } catch (KeyManagementException ex) {
            throw new RuntimeException(ex);
        } catch (NoSuchAlgorithmException ex) {
            throw new RuntimeException(ex);
        }
    }

    /**
     * 将结果转换成JSONObject
     *
     * @param httpResponse
     * @return
     * @throws IOException
     */
    public static JSONObject toJson(HttpResponse httpResponse) throws IOException {
        String resp = getString(httpResponse);
        try {
            return JSON.parseObject(resp);
        } catch (Exception e) {
            log.error("resp:{}", resp, e.getMessage());
        }
        return null;
    }

    public static String getString(HttpResponse httpResponse) {
        if (httpResponse == null) {
            return null;
        }
        try {
            HttpEntity entity = httpResponse.getEntity();
            String resp = EntityUtils.toString(entity, "UTF-8");
            //byte[] bytes = EntityUtils.toByteArray(entity);
            //String resp = new String(bytes);
            EntityUtils.consume(entity);
            return resp;
        } catch (Exception e) {
            log.error("", e);
        }
        return null;

    }


    public static String getQueryString(Map<String, ?> map) {
        StringBuilder buffer = new StringBuilder();
        if (map != null && !map.isEmpty()) {
            Iterator<? extends Map.Entry<String, ?>> iterator = map.entrySet().iterator();
            while (iterator.hasNext()) {
                Map.Entry<String, ?> entry = iterator.next();
                if (entry.getValue() == null || StringUtil.isEmpty(entry.getValue().toString())) {
                    continue;
                }
                if (buffer.length() != 0) {
                    buffer.append("&");
                }
                String value = URLEncoder.encode(entry.getValue().toString());
                buffer.append(entry.getKey()).append("=").append(value);
            }
        }
        return buffer.toString();
    }

    //java对象转map
    public static Map<String, Object> objectToMap(Object obj) {
        if (obj == null) {
            return null;
        }
        try {
            Map<String, Object> map = new HashMap<String, Object>();
            BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass());
            PropertyDescriptor[] propertyDescriptors = beanInfo
                    .getPropertyDescriptors();
            for (PropertyDescriptor property : propertyDescriptors) {
                String key = property.getName();
                if (key.compareToIgnoreCase("class") == 0) {
                    continue;
                }
                Method getter = property.getReadMethod();
                Object value = getter != null ? getter.invoke(obj) : null;
                map.put(key, value);
            }
            return map;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }


    }


    public static ContentType caseContentType(String suffix) {
        if (suffix.contains(".jpeg") || suffix.contains(".jpg")) {
            return ContentType.IMAGE_JPEG;
        } else if (suffix.contains(".gif")) {
            return ContentType.IMAGE_GIF;
        } else if (suffix.contains(".tif")) {
            return ContentType.IMAGE_TIFF;
        } else if (suffix.contains(".webp")) {
            return ContentType.IMAGE_WEBP;
        } else if (suffix.contains(".png")) {
            return ContentType.IMAGE_PNG;
        } else if (suffix.contains(".m3u8")) {
            return ContentType.create("application/vnd.apple.mpegurl");
        } else if (suffix.contains(".apk")) {
            return ContentType.DEFAULT_BINARY;
        } else {
            return ContentType.DEFAULT_BINARY;
        }
    }


    public static void main(String[] args) {
        String s = HttpClientUtils.doGet("https://100c9n4.ukdevilz.com/popular/month", null);
        System.out.println(s);
    }

}

class HttpDeleteWithBody extends HttpEntityEnclosingRequestBase {
    public static final String METHOD_NAME = "DELETE";

    public String getMethod() {
        return METHOD_NAME;
    }

    public HttpDeleteWithBody(final String uri) {
        super();
        setURI(URI.create(uri));
    }

    public HttpDeleteWithBody(final URI uri) {
        super();
        setURI(uri);
    }

    public HttpDeleteWithBody() {
        super();
    }


}